package com.geek.gkmember.util.excp;

import lombok.Getter;

/**
 * <h1>业务异常类。</h1><br/>
 *
 * <h1><br/><a href="https://u.geekbang.org/subject/arch3/100614201">Java 业务架构实战营：https://u.geekbang.org/subject/arch3/100614201</a></h1><br/><h1><a href="https://gitee.com/ylimhhmily/BizArchPracticeCamp">Java 业务架构实战营代码地址：https://gitee.com/ylimhhmily/BizArchPracticeCamp</a></h1><br/><h1><a href="https://u.geekbang.org/subject/java4th/1001148?source=app_share">高级 Java 工程体系课 2023 版：https://u.geekbang.org/subject/java4th/1001148?source=app_share</a></h1><br/><h1><a href="https://time.geekbang.org/column/intro/100312101?tab=catalog">Dubbo 源码剖析与实战：https://time.geekbang.org/column/intro/100312101?tab=catalog</a></h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2022-02-18
 */
@Getter
public class GkMemberException extends RuntimeException {

    /** <h2>异常码</h2> **/
    private String excpCode;

    /** <h2>异常描述</h2> **/
    private String excpMemo;

    public GkMemberException() {
        this(GkMemberCodeEnum.SYSTEM_EXCEPTION);
    }

    public GkMemberException(String message) {
        this(GkMemberCodeEnum.SYSTEM_EXCEPTION, message);
    }

    public GkMemberException(Throwable cause) {
        this(GkMemberCodeEnum.SYSTEM_EXCEPTION, cause);
    }

    public GkMemberException(String excpCode, String message) {
        super("[" + excpCode + "]" + message);
        this.excpCode = excpCode;
        this.excpMemo = message;
    }

    public GkMemberException(String message, Throwable cause) {
        this(GkMemberCodeEnum.SYSTEM_EXCEPTION.getCode(),
                GkMemberCodeEnum.SYSTEM_EXCEPTION.getMsg() + ":" + message, cause);
    }

    public GkMemberException(String excpCode, String message, Throwable cause) {
        super("[" + excpCode + "]" + message, cause);
        this.excpCode = excpCode;
        this.excpMemo = message;
    }

    public GkMemberException(GkMemberCodeEnum gkMemberCodeEnum) {
        super("[" + gkMemberCodeEnum.getCode() + "]" + gkMemberCodeEnum.getMsg());
        this.excpCode = gkMemberCodeEnum.getCode();
        this.excpMemo = gkMemberCodeEnum.getMsg();
    }

    public GkMemberException(GkMemberCodeEnum gkMemberCodeEnum, String extraMsg) {
        super("[" + gkMemberCodeEnum.getCode() + "]" + gkMemberCodeEnum.getMsg() + ":" + extraMsg);
        this.excpCode = gkMemberCodeEnum.getCode();
        this.excpMemo = gkMemberCodeEnum.getMsg() + ":" + extraMsg;
    }

    public GkMemberException(GkMemberCodeEnum gkMemberCodeEnum, Throwable cause) {
        super("[" + gkMemberCodeEnum.getCode() + "]" + gkMemberCodeEnum.getMsg(), cause);
        this.excpCode = gkMemberCodeEnum.getCode();
        this.excpMemo = gkMemberCodeEnum.getMsg();
    }

    public GkMemberException(GkMemberCodeEnum gkMemberCodeEnum, String extraMsg, Throwable cause) {
        super("[" + gkMemberCodeEnum.getCode() + "]" + gkMemberCodeEnum.getMsg() + ":" + extraMsg, cause);
        this.excpCode = gkMemberCodeEnum.getCode();
        this.excpMemo = gkMemberCodeEnum.getMsg() + ":" + extraMsg;
    }
}